using System.Linq;
using System.Text;
using Common;
using Common.Enum;
using Converters;
using SExperiment;
using SExperiment.ExperimentResult;
using SProject.Paramter;
using SWellPlate;

namespace MainView.MainControls.Chart
{
	public abstract class BaseHRMCurveChart : BaseCurveChart
	{
		protected override string GetToolTipString(ChartData chartData)
		{
			BasicOption basicOption = base.Subset.GetSubsetParamter(chartData.WellCell.Well.Project).BasicOption;
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine(Utility.GetMessage("well_no") + Utility.GetMessage("Colon") + chartData.WellCell.Well.CellName);
			stringBuilder.AppendLine(Utility.GetMessage("Channel") + Utility.GetMessage("Colon") + chartData.SampleTargetItem.ChannelNo);
			stringBuilder.AppendLine(Utility.GetMessage("Target") + Utility.GetMessage("Colon") + chartData.SampleTargetItem.TargetName);
			stringBuilder.AppendLine(Utility.GetMessage("Type") + Utility.GetMessage("Colon") + EnumManagement.GetSampleTypeName(chartData.SampleTargetItem.SampleType));
			stringBuilder.AppendLine(Utility.GetMessage("patient_name") + Utility.GetMessage("Colon") + chartData.WellCell.Well.Sample.PatientInfo.Name);
			stringBuilder.AppendLine(Utility.GetMessage("sample_name") + Utility.GetMessage("Colon") + chartData.WellCell.Well.Sample.SampleName);
			stringBuilder.AppendLine(Utility.GetMessage("typing") + Utility.GetMessage("Colon") + GetTyping(chartData));
			stringBuilder.AppendLine(Utility.GetMessage("quality_factor") + Utility.GetMessage("Colon") + ResultFormat.Format(((HRMTargetResult)chartData.SampleTargetItem.Result).QualityFactor, "#,0.00"));
			stringBuilder.AppendLine(base.TitleX + Utility.GetMessage("Colon") + "#VAL{X}");
			stringBuilder.AppendLine(base.TitleY + Utility.GetMessage("Colon") + "#VALX{Y}");
			return stringBuilder.ToString();
		}

		private string GetTyping(ChartData chartData)
		{
			string result = string.Empty;
			Subset.SubsetParamter subsetParamter = base.Subset.GetSubsetParamter(chartData.WellCell.Well.Project);
			if (subsetParamter != null)
			{
				HRMOptionItem hRMOptionItem = subsetParamter.BasicOption.Items.Where((BasicOptionItem s) => s.TargetName == chartData.SampleTargetItem.TargetName).FirstOrDefault() as HRMOptionItem;
				if (hRMOptionItem != null)
				{
					result = ((hRMOptionItem.TypeMethod != 0) ? ((HRMTargetResult)chartData.SampleTargetItem.Result).GenoName : base.Subset.GenoTypeList.Where((KeyValuePair s) => (EGenoType)s.Key == ((HRMTargetResult)chartData.SampleTargetItem.Result).GenoType).FirstOrDefault().Value.ToString());
				}
			}
			return result;
		}
	}
}
